﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;


public partial class 序列化类型_反射出類型裏的成員 : System.Web.UI.Page
{
    Tong.TongUse MyDt = new Tong.TongUse();
    protected void Page_Load(object sender, EventArgs e)
    {
        //反射DataTabl();
        //反射 DataTable 试试

        ///显示数据
        string stringData = "\"INSERT INTO [CX_NEWS_Class] (\"\r\n";
        string StringPareames = "";//显示参数
        foreach (System.Reflection.PropertyInfo p in GetMembers( ((bb)new aa()).GetType() ) )
        {
            Response.Write(string.Format("属性名:{0}:类型{1}:返回类型{2}", p.Name, p.MemberType.ToString(), p.PropertyType) + "<br/>");
            stringData +=" \"\t\t\t";
            stringData += p.Name+"\"\r\n";



        }

        Response.Write(stringData.Replace("\r\n", "+\r\n")
            + "\r\n" + stringData.Replace("\t\t\t", "\t\t\t@").Replace("\r\n", "+\r\n"));
    }
    void 反射DataTabl    ()
    {
        ///用於执行反射的操作类型
        //返回当前类型的
        foreach (System.Reflection.PropertyInfo p in typeof(DataTable).GetProperties())
        {
            Response.Write(string.Format("属性名:{0}:类型{1}:返回类型{2}",p.Name,p.MemberType.ToString(),p.PropertyType)+"<br/>");
        }
    }

    /// <summary>
    /// 数据库表映射类的公共属性
    /// </summary>
    private System.Reflection.PropertyInfo[] MyDataTableMembers;

    /// <summary>
    /// 得到传入对像的成员 返回下面所有的属性
    /// </summary>
    /// <param name="type">传入 实现 IDataBaseTable接口的数据库操作对像 </param>
    /// <returns></returns>
    private System.Reflection.PropertyInfo[] GetMembers(Type type)
    {

        MyDataTableMembers = new System.Reflection.PropertyInfo[type.GetProperties().Length];//设定初始长度

        for (int i = 0; i < type.GetProperties().Length;i++ )
        {
            MyDataTableMembers[i] = type.GetProperties()[i];

        }

        return MyDataTableMembers;
    }
}

interface bb {

    string oo { get; }
    
}
class aa : bb
{
    #region bb 成员

    public string oo
    {
        get { return "dfsdf"; }
    }

    #endregion

    public string ppp
    { get; set; }

    public int sss { get; set; }

    public int bbbo { get; set; }
}